<?php

session_start();
require_once('../config.php');

require_once($CONFIG->datadir.'/lib/db/DB.php');
require_once($CONFIG->datadir.'/search/lib/searchlib.php');
require_once($CONFIG->datadir.'/lib/outputlib.php');
require_once($CONFIG->datadir.'/lib/mainlib.php');

getSessionTab();
getSessionLang();
include_once($CONFIG->datadir.'/lang/'.$_SESSION["lang"].'.php');

// DB instance
$DB = new DB();

// If there are no search redirect
if (empty($_GET['q']) OR $_GET['q'] == '') {
    header('location:'.$CONFIG->webdir);
} 


if (!empty($_GET["q"]) && $_SESSION["q"] != '' && $_GET["q"] != $_SESSION["q"]) {
    unset($_SESSION['total']);
}
if (!empty($_GET["q"])) {
    $_SESSION["q"] = $_GET["q"];
}
if (isset($_GET["meta"])) {
    $_SESSION["meta"] = $_GET["meta"];
}


showHead();

?>


<table valign="top" align="left" width="100%"><tr><td align="left">

<?php showTabLinks($CONFIG->webdir.'/search/'); ?>

<br /><br />

<form action="<?php echo $CONFIG->webdir;?>/search/" name="form">
<table><tr><td>
<a href="<?php echo $CONFIG->webdir;?>"><img border="0" height="55" width="145" src="<?php echo $CONFIG->webdir;?>/styles/<?php echo $CONFIG->style_name;?>/img/logo.jpeg" alt="Blooglebot" /></a>
</td><td valign="bottom">
<input name="q" size="55" title="<?php echo $string['blooglesearch'];?>" value="<?php echo $_SESSION['q'];?>" /><br />
<?php echo $string['searchin'];?>&nbsp;
<input name="meta" type="radio" value="" <?php if (empty($_SESSION['meta']) OR $_SESSION['meta'] == '') { echo 'checked=yes';}?> />&nbsp;<?php echo $string['web'];?>&nbsp;
<input name="meta" type="radio" value="<?php echo $_SESSION['lang'];?>" <?php if ($_SESSION['meta'] == $_SESSION['lang']) { echo 'checked=yes';}?>/>&nbsp;<?php echo $string['pagesin'].' '.$string[$_SESSION['lang']];?>&nbsp;
</td><td>
<input name="send" type="submit" value="<?php echo $string['search'];?>" />
</td></tr></table>
</form>
</td></tr>
<tr><td>  

<?php

  $q = $_GET["q"];
  if (!empty($_GET["meta"])) { $meta = $_GET["meta"];}
  else{ $meta = $_SESSION["meta"];}
  if (!empty($_GET["start"])) { $start = $_GET["start"];}
  else{ $start = 0;}

  // LLIMPIAR Q DE SQL-INJECTION!!!

  switch ($_SESSION["tab"]) {
    case 'l':
        labelsearch($q, $start);
        break;
    case 't':
        titlesearch($q, $start);
        break;
    case 'i':
        mediasearch($q, 'images', $start);
        break;
    case 'v':
        mediasearch($q, 'videos', $start);
        break;
    case 's':
        mediasearch($q, 'sounds', $start);
        break;
    default:
        titlesearch($q, $start);
        break;
  }

showFoot();

?>

</td></tr>
</table>
